<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "edu_appear".
 *
 * @property int $id
 * @property string $openid 用户openid
 * @property string $amount 申请金额
 * @property int $status 1提现中 | 审核中 2 提现成功 3提现失败 并返还到
 * @property string $reason 原因
 * @property int $create_time 创建时间
 * @property int $finish_time 完成时间
 * @property int $check_id 操作完成者
 */
class EduAppear extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'edu_appear';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['openid', 'create_time'], 'required'],
            [['amount'], 'number'],
            [['status', 'create_time', 'finish_time', 'check_id'], 'integer'],
            [['openid'], 'string', 'max' => 100],
            [['reason'], 'string', 'max' => 500],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'openid' => 'Openid',
            'amount' => '提现金额',
            'status' => '提现状态',
            'reason' => '原因',
            'create_time' => '申请时间',
            'finish_time' => '完成时间',
            'check_id' => '操作账号',
        ];
    }

    /**
     * 跟用户表关联
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(EduUser::class, ['openid' => 'openid']);
    }

    /**
     * 跟门店关联
     * @return \yii\db\ActiveQuery
     */
    public function getDot()
    {
        return $this->hasOne(EduDot::class, ['openid' => 'openid']);
    }

    /**
     * 状态枚举
     * @return array
     */
    public static function attributeValue()
    {
        return [
            'status' => [
                '1' => '提现中',
                '2' => '提现成功',
                '3' => '提现失败',
            ],
        ];
    }

    /**
     * status枚举
     * @return string
     */
    public function getStatusValue()
    {
        switch ($this->status)
        {
            case 1:
                $value = '提现中';
                break;
            case 2:
                $value = '提现成功';
                break;
            case 3:
                $value = '提现失败';
                break;
            default:
                $value = '其他';
                break;
        }
        return $value;
    }
}
